import os
import uuid
import cv2
import torch

def worker_process_image(image_path):
    output_dir = "./output"
    os.makedirs(output_dir, exist_ok=True)

    #生成唯一的输出文件名
    output_filename = f"processed_image_{uuid.uuid4().hex}.jpg"
    output_path = os.path.join(output_dir, output_filename)

    #加载模型
    model = torch.hub.load('./yolov5', 'custom', path='./models/yolov5s.pt', source='local')
    #读取图片
    frame = cv2.imread(image_path)


    #进行图片的检测
    result = model(frame)


    #渲染结果
    rendered_frame = result.render()[0]

    #保存结果
    cv2.imwrite(output_path,rendered_frame)

    #显示结果
    cv2.imshow("result",rendered_frame)
    cv2.waitKey(0)
    cv2.destroyAllWindows()